<template>
	<view class="mine" :class="theme+'-bg-middle'">
		<view class="user">
			<view class="appClass">
				<text :class="theme + '-ftext-color'">亿个内涵</text>
			</view>
			<!-- #ifdef H5 -->
			<view class="userClass">
				<text :class="theme + '-ftext-color'">
					{{`hello ${userInformation.phone?userInformation.phone:''} Current 999 Tools`}}
				</text>
			</view>
			<!-- #endif -->
			<!-- #ifdef APP-PLUS -->
			<view class="userClass">
				<text :class="theme + '-ftext-color'">
				{{`hello ${userInformation.phone?userInformation.phone:''} Current 999 Tools`}}
				</text>
			</view>
			<!-- #endif -->
			<!-- #ifdef MP-WEIXIN -->
			<view class=" userClass">
					<text :class="theme + '-ftext-color'">
						{{`hello ${userInformation.nickname?userInformation.nickname:''} Current 999 Tools`}}
					</text>
			</view>
			<!-- #endif -->
		</view>
		<!-- #ifdef H5 -->
		<view :class="['navBox',`${item.ber?`${theme}-border-top ${theme}-border-bottom`:''}`]" v-for="item in data"
			:key="item.id">
			<view class="nav" v-for="ele in item.list" :key="ele.id" @click="ele.text=='退出'?quit():go(ele.link)">
				<view class="nav-l">
					<view class="icon">
						<image :src="ele.icon"></image>
					</view>
					<view class="text">
						<text :class="theme + '-ftext-color'">{{locale=='en'?ele.english:ele.text}}</text>
					</view>
				</view>
				<view class="nav-r">
					<view class="icon">
						<image src="../../static/images/icons/jinrujiantou.png"></image>
					</view>
				</view>
			</view>

		</view>
		<!-- #endif   -->
		<!-- #ifdef APP-PLUS -->
		<view :class="['navBox',`${item.ber?`${theme}-border-top ${theme}-border-bottom`:''}`]" v-for="item in data"
			:key="item.id">
			<view class="nav" v-for="ele in item.list" :key="ele.id" @click="ele.text=='退出'?quit():go(ele.link)">
				<view class="nav-l">
					<view class="icon">
						<image :src="ele.icon"></image>
					</view>
					<view class="text">
						<text :class="theme + '-ftext-color'">{{locale=='en'?ele.english:ele.text}}</text>
					</view>
				</view>
				<view class="nav-r">
					<view class="icon">
						<image src="../../static/images/icons/jinrujiantou.png"></image>
					</view>
				</view>
			</view>

		</view>
		<!-- #endif   -->
		<!-- #ifdef MP-WEIXIN -->
		<view :class="['navBox',`${item.ber?`${theme}-border-top ${theme}-border-bottom`:''}`]" v-for="item in data"
			:key="item.id">
			<view class="nav" v-for="ele in item.list" :key="ele.id" v-if="ele.text!='退出'"
				@click="ele.text=='退出'?quit():go(ele.link)">
				<view class="nav-l">
					<view class="icon">
						<image :src="ele.icon"></image>
					</view>
					<view class="text">
						<text :class="theme + '-ftext-color'">{{locale=='en'?ele.english:ele.text}}</text>
					</view>
				</view>
				<view class="nav-r">
					<view class="icon">
						<image src="../../static/images/icons/jinrujiantou.png"></image>
					</view>
				</view>
			</view>
		</view>
		<!-- #endif   -->
	</view>
</template>

<script>
	export default {
		// 我的页面
		data() {
			return {
				data: [{
					list: [{
						text: '我的账户',
						english: 'Myaccount',
						icon: '../../static/images/icons/wodezhanghu.png',
						link: './my-account/MyAccount'
					}]
				}, {
					ber: true,
					list: [{
							text: '全部应用',
							english: 'Allapplications',
							icon: '../../static/images/icons/quanbuyingyong.png',
							link: '../category/whole/Whole'
						}, {
							text: '收藏同步',
							english: 'Synchronize',
							icon: '../../static/images/icons/yonghutongbu.png',
							link: './synchronization/Synchronization'
						},
						{
							text: '主题管理',
							english: 'Thememanagement',
							icon: '../../static/images/icons/zhutiguanli.png',
							link: './theme/Theme'
						},
					]
				}, {
					list: [{
							text: '设置',
							english: 'Setup',
							icon: '../../static/images/icons/shezhi.png',
							link: './setup/Setup'
						},
						// {
						// 	text: '关于',
						// 	english:'About',
						// 	icon: '../../static/images/icons/guanyuwomen.png',
						// 	link: './about/About'
						// },
						{
							text: '退出',
							english: 'Quit',
							icon: '../../static/images/icons/tuic.png',
							link: ''
						}
					]
				}],
				userInformation: uni.getStorageSync('userInformation'),
			}
		},
		onLoad() {
			this.$theme()
		},
		onShow() {
			this.$theme()
			this.userInformation = uni.getStorageSync('userInformation')
		},
		methods: {
			go(link) {
				if (link == './my-account/MyAccount') {
					if (!uni.getStorageSync('userInformation')) {
						// #ifdef H5
						uni.showToast({
							title: '还未登录呢，即将跳转登录',
							icon: 'none'
						})
						setTimeout(() => {
							uni.navigateTo({
								url: './my-account/login/Login',
							})
						}, 1000)
						// #endif
						// #ifdef APP-PLUS
						uni.showToast({
							title: '还未登录呢，即将跳转登录',
							icon: 'none'
						})
						setTimeout(() => {
							uni.navigateTo({
								url: './my-account/login/Login',
							})
						}, 1000)
						// #endif
						// #ifdef MP-WEIXIN
						uni.showToast({
							title: '还未登录呢，请先登录',
							icon: 'none'
						})
						this.weChatLogin()
						// #endif
					} else {
						uni.navigateTo({
							url: link
						})
					}
				} else {
					uni.navigateTo({
						url: link
					})
				}
			},
			quit() {
				// #ifdef APP-PLUS  
				plus.runtime.quit();
				// #endif
			},
			weChatLogin() {
				//#ifdef MP-WEIXIN
				uni.checkSession({
					success: (res) => {
						console.log(res)
					},
					fail: (err) => {
						console.log(err)
					}
				})
				uni.getUserProfile({
					desc: '登录',
					success: (res1) => {
						// console.log(res1.userInfo)
						uni.showLoading({
							title: '登录中...'
						})
						uni.getProvider({
							service: 'oauth',
							success: (res2) => {
								// console.log(res2)
								if (~res2.provider.indexOf('weixin')) {
									uni.login({
										provider: 'weixin',
										success: (res3) => {
											// console.log(res3)

											this.$post('/login/wx-mini', {
												code: res3.code
											}).then(res4 => {

												// console.log(res4.data)
												uni.hideLoading()
												uni.showToast({
													title: "登录成功",
													icon: 'none'
												});
												res4.data.nickname = res1
													.userInfo.nickName
												this.userInformation = res4
													.data
												uni.setStorage({
													key: 'userInformation',
													data: res4.data
												})
											})
										},
										fail: () => {
											uni.showToast({
												title: "微信登录授权失败",
												icon: "none"
											});
										}
									})

								} else {
									uni.showToast({
										title: '请先安装微信或升级版本',
										icon: "none"
									});
								}
							}
						});
					},
					fail: () => {
						// console.log(777)
						// uni.showToast({
						// 	title: "微信登录授权失败",
						// 	icon: "none"
						// });
					}
				})
				//#endif
			}
		}
	}
</script>

<style lang="scss">
	.mine {
		height: 100%;

		.user {
			height: 270rpx;
			background-image: url(https://img0.baidu.com/it/u=2543033050,170604662&fm=26&fmt=auto&gp=0.jpg);
			opacity: 0.5;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			cursor: pointer;

			.appClass {
				margin-bottom: 30rpx;

				text {
					font-size: 45rpx;
				}
			}

			.userClass {
				text {
					font-size: 18rpx;
				}
			}
		}

		.navBox {
			padding: 15rpx 0;

			.nav {
				height: 95rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-left: 48rpx;
				cursor: pointer;

				.nav-l {
					display: flex;
					align-items: center;
				}

				.icon {
					width: 40rpx;
					height: 40rpx;
					margin-right: 30rpx;
				}

				.text {
					text {
						font-size: 26rpx;
						cursor: pointer;
					}
				}
			}
		}
	}
</style>
